package com.example.grpc.service.helloworld;

import io.grpc.Server;
import io.grpc.ServerBuilder;

import java.io.IOException;

public class GretterService {
    public static void main(String[] args) throws IOException, InterruptedException {
        Server server = ServerBuilder.forPort(30010)
                .addService(new GreeterServiceImpl())
                .build();
        server.start();
        // Just add shutdown hook of Java runtime
        Runtime.getRuntime().addShutdownHook(new Thread(() -> {
            System.out.println("Server is shutdowning ...");
            // Call this to shutdown server
            server.shutdown();
            System.out.println("Server has shutdowned");
        }));

        // We have to wait for the Server shutdowned, if not the program will be halted.
        server.awaitTermination();
    }
}
